//
//  HYMainTabBarController.swift
//  iOSWeibo
//
//  Created by why on 16/7/18.
//  Copyright © 2016年 王浩宇. All rights reserved.
//

import UIKit

class HYMainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainTabBar = HYMainTabBar()
        
        mainTabBar.composeCallback = {() -> Void in
            print("我在控制器里面知道加号按钮点击了")
        }
        
        self.setValue(mainTabBar, forKey: "tabBar")

        addChildViewController()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func addChildViewController() {
        
        let homeVC = HYHomeTableViewController()
        addChildViewController(homeVC, title: "首页", imageName: "tabbar_home")
        
        let messageVC = HYMessageTableViewController()
        addChildViewController(messageVC, title: "消息", imageName: "tabbar_message_center")
        
        let discoveryVC = HYDiscoverTableViewController()
        addChildViewController(discoveryVC, title: "发现", imageName: "tabbar_discover")
        
        let profileVC = HYProfileTableViewController()
        addChildViewController(profileVC, title: "我", imageName: "tabbar_profile")
        
    }

    func addChildViewController(controller: UIViewController, title: String, imageName: String)
    {
        controller.title = title;
        
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        
        controller.tabBarItem.image = UIImage(named: imageName)
        
        let selectedImageName = imageName + "_selected"
        
        controller.tabBarItem.selectedImage = UIImage(named: selectedImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        self.addChildViewController(UINavigationController(rootViewController: controller))
    }

}
